﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MailSharpTestApp
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void btnLoadTemplateFile_Click(object sender, EventArgs e)
    {
      MailSharp.TemplateInfo template = MailSharp.TemplateInfo.LoadFromFile(txtTemplateFolder.Text + txtTemplateFileName.Text);

      txtTemplateSource.Text = template.Content;
      webBrowser1.Navigate(txtTemplateFolder.Text + txtTemplateFileName.Text);

      foreach (string s in template.ImageFileNames)
      {
        listBox1.Items.Add(s);
      }

    }

    private void btnSendEmail_Click(object sender, EventArgs e)
    {
      MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
      conn.ConnectionString = "Server=localhost;Database=ardentdev;Uid=root;Pwd=Password1;";

      
      MailSharp.Mailer mlr = new MailSharp.Mailer(conn, txtTemplateFolder.Text,
                                                  txtSmtpServer.Text,
                                                  int.Parse(txtSmtpServerPort.Text),
                                                  txtUsername.Text,
                                                  txtPassword.Text,
                                                  chkSSL.Checked);
      MailSharp.RecipientInfo recip = new MailSharp.RecipientInfo(txtRecipient.Text, txtRecipientEmail.Text);
      MailSharp.SenderInfo sending = new MailSharp.SenderInfo();
      sending.FromEmail = txtFromEmail.Text;
      sending.FromName = txtFromName.Text;

      mlr.SendNowUsingTemplate(recip, sending, "Test from MailSharp", txtTemplateFileName.Text);

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
  }
}
